﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_ZW_DIXIASXX实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_ZW_DIXIASXX
    {
        private double? m_db_n_benyuedz;

        private double? m_db_n_benyuekz;

        private double? m_db_n_benyuetp;

        private double? m_db_n_dixiasbs;

        private decimal m_dec_i_jlzt;

        private decimal? m_dec_i_m;

        private decimal m_dec_i_y;

        private decimal m_dec_id;

        private DateTime? m_DT_d_createdate;

        private DateTime? m_DT_d_modifydate;

        private string m_str_s_createuser;

        private string m_str_s_modifyuser;

        /// <summary>
        ///     主键
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     开账年
        /// </summary>
        public decimal I_Y
        {
            get { return m_dec_i_y; }
            set { m_dec_i_y = value; }
        }

        /// <summary>
        ///     开账月
        /// </summary>
        public decimal? I_M
        {
            get { return m_dec_i_m; }
            set { m_dec_i_m = value; }
        }

        /// <summary>
        ///     本月开账金额
        /// </summary>
        public double? N_BENYUEKZ
        {
            get { return m_db_n_benyuekz; }
            set { m_db_n_benyuekz = value; }
        }

        /// <summary>
        ///     本月到账金额
        /// </summary>
        public double? N_BENYUEDZ
        {
            get { return m_db_n_benyuedz; }
            set { m_db_n_benyuedz = value; }
        }

        /// <summary>
        ///     本月退票金额
        /// </summary>
        public double? N_BENYUETP
        {
            get { return m_db_n_benyuetp; }
            set { m_db_n_benyuetp = value; }
        }

        /// <summary>
        ///     地下水不收
        /// </summary>
        public double? N_DIXIASBS
        {
            get { return m_db_n_dixiasbs; }
            set { m_db_n_dixiasbs = value; }
        }

        /// <summary>
        ///     是否逻辑删除
        /// </summary>
        public decimal I_JLZT
        {
            get { return m_dec_i_jlzt; }
            set { m_dec_i_jlzt = value; }
        }

        /// <summary>
        ///     创建人
        /// </summary>
        public string S_CREATEUSER
        {
            get { return m_str_s_createuser; }
            set { m_str_s_createuser = value; }
        }

        /// <summary>
        ///     创建日期
        /// </summary>
        public DateTime? D_CREATEDATE
        {
            get { return m_DT_d_createdate; }
            set { m_DT_d_createdate = value; }
        }

        /// <summary>
        ///     修改人
        /// </summary>
        public string S_MODIFYUSER
        {
            get { return m_str_s_modifyuser; }
            set { m_str_s_modifyuser = value; }
        }

        /// <summary>
        ///     修改日期
        /// </summary>
        public DateTime? D_MODIFYDATE
        {
            get { return m_DT_d_modifydate; }
            set { m_DT_d_modifydate = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class YS_ZW_DIXIASXXProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_ZW_DIXIASXXProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据YS_ZW_DIXIASXX实体添加或者修改YS_ZW_DIXIASXX信息
        /// </summary>
        public bool InsertOrUpdate(YS_ZW_DIXIASXX YS_ZW_DIXIASXX, OracleTransaction Transaction)
        {
            if (YS_ZW_DIXIASXX.ID == 0)
                InsertYS_ZW_DIXIASXX(YS_ZW_DIXIASXX, Transaction);
            else
                UpdateYS_ZW_DIXIASXX(YS_ZW_DIXIASXX, Transaction);
            return YS_ZW_DIXIASXX.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_ZW_DIXIASXX实体添加或修改YS_ZW_DIXIASXX信息
        /// </summary>
        public bool InsertOrUpdate(YS_ZW_DIXIASXX YS_ZW_DIXIASXX)
        {
            return InsertOrUpdate(YS_ZW_DIXIASXX, null);
        }


        /// <summary>
        ///     根据YS_ZW_DIXIASXX主键删除YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_ZW_DIXIASXX(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_ZW_DIXIASXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_ZW_DIXIASXX主键删除YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_ZW_DIXIASXX(decimal ID)
        {
            return DeleteYS_ZW_DIXIASXX(ID, null);
        }

        /// <summary>
        ///     根据条件删除YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_ZW_DIXIASXXesDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_ZW_DIXIASXXesDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_ZW_DIXIASXXesDynamic(string WhereClause)
        {
            return DeleteYS_ZW_DIXIASXXesDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据YS_ZW_DIXIASXX主键选择YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_DIXIASXX信息</returns>
        public YS_ZW_DIXIASXX SelectYS_ZW_DIXIASXX(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_DIXIASXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var YS_ZW_DIXIASXX = PopulateYS_ZW_DIXIASXX(rd);
                rd.Close();
                return YS_ZW_DIXIASXX;
            }
            return null;
        }

        /// <summary>
        ///     根据YS_ZW_DIXIASXX主键选择YS_ZW_DIXIASXX信息
        /// </summary>
        /// <returns>YS_ZW_DIXIASXX信息</returns>
        public YS_ZW_DIXIASXX SelectYS_ZW_DIXIASXX(decimal ID)
        {
            return SelectYS_ZW_DIXIASXX(ID, null);
        }

        /// <summary>
        ///     选择所有YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_ZW_DIXIASXX信息</returns>
        public DataTable SelectYS_ZW_DIXIASXXesAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_DIXIASXXesAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有YS_ZW_DIXIASXX信息
        /// </summary>
        /// <returns>所有YS_ZW_DIXIASXX信息</returns>
        public DataTable SelectYS_ZW_DIXIASXXesAll()
        {
            return SelectYS_ZW_DIXIASXXesAll(null);
        }

        /// <summary>
        ///     根据条件选择YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_DIXIASXX信息</returns>
        public DataTable SelectYS_ZW_DIXIASXXesDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_DIXIASXXesDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_ZW_DIXIASXX信息</returns>
        public DataTable SelectYS_ZW_DIXIASXXesDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_ZW_DIXIASXXesDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_DIXIASXX信息</returns>
        public DataTable SelectYS_ZW_DIXIASXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_DIXIASXXesDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_ZW_DIXIASXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_ZW_DIXIASXX信息</returns>
        public DataTable SelectYS_ZW_DIXIASXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectYS_ZW_DIXIASXXesDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新YS_ZW_DIXIASXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_ZW_DIXIASXXesDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdYS_ZW_DIXIASXXDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新YS_ZW_DIXIASXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_ZW_DIXIASXXesDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_ZW_DIXIASXXesDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertYS_ZW_DIXIASXX(YS_ZW_DIXIASXX YS_ZW_DIXIASXX, OracleTransaction Transaction)
        {
            var spName = "CS_InsYS_ZW_DIXIASXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_ZW_DIXIASXX.I_Y;
            storedParams[1].Value = YS_ZW_DIXIASXX.I_M;
            storedParams[2].Value = YS_ZW_DIXIASXX.N_BENYUEKZ;
            storedParams[3].Value = YS_ZW_DIXIASXX.N_BENYUEDZ;
            storedParams[4].Value = YS_ZW_DIXIASXX.N_BENYUETP;
            storedParams[5].Value = YS_ZW_DIXIASXX.N_DIXIASBS;
            storedParams[6].Value = YS_ZW_DIXIASXX.I_JLZT;
            storedParams[7].Value = YS_ZW_DIXIASXX.S_CREATEUSER;
            storedParams[8].Value = YS_ZW_DIXIASXX.D_CREATEDATE;
            storedParams[9].Value = YS_ZW_DIXIASXX.S_MODIFYUSER;
            storedParams[10].Value = YS_ZW_DIXIASXX.D_MODIFYDATE;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_ZW_DIXIASXX.ID = Convert.ToInt32(storedParams[11].Value);
            return result;
        }

        private bool UpdateYS_ZW_DIXIASXX(YS_ZW_DIXIASXX YS_ZW_DIXIASXX, OracleTransaction Transaction)
        {
            var spName = "CS_UpdYS_ZW_DIXIASXX";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_ZW_DIXIASXX.I_Y;
            storedParams[1].Value = YS_ZW_DIXIASXX.I_M;
            storedParams[2].Value = YS_ZW_DIXIASXX.N_BENYUEKZ;
            storedParams[3].Value = YS_ZW_DIXIASXX.N_BENYUEDZ;
            storedParams[4].Value = YS_ZW_DIXIASXX.N_BENYUETP;
            storedParams[5].Value = YS_ZW_DIXIASXX.N_DIXIASBS;
            storedParams[6].Value = YS_ZW_DIXIASXX.I_JLZT;
            storedParams[7].Value = YS_ZW_DIXIASXX.S_CREATEUSER;
            storedParams[8].Value = YS_ZW_DIXIASXX.D_CREATEDATE;
            storedParams[9].Value = YS_ZW_DIXIASXX.S_MODIFYUSER;
            storedParams[10].Value = YS_ZW_DIXIASXX.D_MODIFYDATE;
            storedParams[11].Value = YS_ZW_DIXIASXX.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_ZW_DIXIASXX PopulateYS_ZW_DIXIASXX(IDataReader dr)
        {
            var YS_ZW_DIXIASXX = new YS_ZW_DIXIASXX();
            YS_ZW_DIXIASXX.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            YS_ZW_DIXIASXX.I_Y = dr["I_Y"] == DBNull.Value ? 0 : (decimal) dr["I_Y"];
            YS_ZW_DIXIASXX.I_M = dr["I_M"] == DBNull.Value ? null : (decimal?) dr["I_M"];
            YS_ZW_DIXIASXX.N_BENYUEKZ = dr["N_BENYUEKZ"] == DBNull.Value ? null : (double?) dr["N_BENYUEKZ"];
            YS_ZW_DIXIASXX.N_BENYUEDZ = dr["N_BENYUEDZ"] == DBNull.Value ? null : (double?) dr["N_BENYUEDZ"];
            YS_ZW_DIXIASXX.N_BENYUETP = dr["N_BENYUETP"] == DBNull.Value ? null : (double?) dr["N_BENYUETP"];
            YS_ZW_DIXIASXX.N_DIXIASBS = dr["N_DIXIASBS"] == DBNull.Value ? null : (double?) dr["N_DIXIASBS"];
            YS_ZW_DIXIASXX.I_JLZT = dr["I_JLZT"] == DBNull.Value ? 0 : (decimal) dr["I_JLZT"];
            YS_ZW_DIXIASXX.S_CREATEUSER = dr["S_CREATEUSER"] == DBNull.Value ? null : (string) dr["S_CREATEUSER"];
            YS_ZW_DIXIASXX.D_CREATEDATE = dr["D_CREATEDATE"] == DBNull.Value ? null : (DateTime?) dr["D_CREATEDATE"];
            YS_ZW_DIXIASXX.S_MODIFYUSER = dr["S_MODIFYUSER"] == DBNull.Value ? null : (string) dr["S_MODIFYUSER"];
            YS_ZW_DIXIASXX.D_MODIFYDATE = dr["D_MODIFYDATE"] == DBNull.Value ? null : (DateTime?) dr["D_MODIFYDATE"];
            return YS_ZW_DIXIASXX;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion